package com.lagou.dao;

import com.lagou.entity.User;
import com.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;


public class UserDaoImplement implements UserDao {

    /*

        用户登陆方法

     */

    @Override

    public User login(String name, String password) throws SQLException {

        QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());

        String sql = "select * from user where name = ? and password = ?";

        Object[] param = {name, password};

        User user = queryRunner.query(sql, new BeanHandler<>(User.class), param);

        return user;

    }



    /*

        用户添加方法

     */

    @Override

    public void addUser(User user) throws SQLException {


        QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
        System.out.println(user.getBirthday()+"$$$$$$$");

        String sql = "insert into user(s_no,name,password,birthday,sex) values(?,?,?,?,?)";

        Object[] param = {user.getsNo(), user.getName(), user.getPassword(), user.getBirthday(), user.getSex()};

        queryRunner.update(sql, param);

    }

}